package com.yf.gogameserver.service;/*
@author FAN

@create 2021-12-21-10:34


*/

import com.yf.gogameserver.entity.User;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    private List<User> userList = new ArrayList<>();

    //模拟注册
    @Override
    public int register(User user) {
        //循环List
        for (User user1 : userList) {
            //判断当前用户是否存在
            if (user1.getUsername().equals(user.getUsername())) {
                //注册用户名与集合中用户名一样
                return -1;//用户名重复，-1
            }
            //当前邮箱是否重复
            if (user1.getEmail().equals(user.getEmail())) {
                return -2;//邮箱重复
            }
        }
        //添加用户
        userList.add(user);
        return 1;//注册用户
    }

    @Override
    public User login(String username, String password) {
        for (User user : userList) {
            if (user.getUsername().equals(username) && user.getPassword().equals(password)) {
                //已经找到用户名和密码
                return user;
            }
        }


        return null;
    }

    @Override
    public int sendEmailByUserName(String username) {
        return 0;
    }

    @Override
    public int updatePassword(String username, String newPassword) {
        return 0;
    }

    @Override
    public int updateHeader(String username, String header) {
        return 0;
    }

}